package com.zeny.web;

import com.zeny.utils.LogBean;
import com.zeny.utils.LogInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName ApiService
 * @Description TODO
 * @Author zeny
 */
@Service
public class ApiService {
    @Autowired
    private RestTemplate restTemplate;

    private final static Logger logger = LoggerFactory.getLogger("kafka");

    @LogInfo
    public void test() {
        LogBean logBean = LogBean.logBeanThreadLocal.get();
        logBean.setMessage("I am service");
        logger.info(logBean.toString());
        logBean.setMessage("before call user");
        logger.info(logBean.toString());
        String res = restTemplate.getForObject("http://user/info", String.class);
        logBean.setMessage("after call user, res=" + res);
        logger.info(logBean.toString());
    }

    @LogInfo
    public boolean login(String username, String password) {
        return  restTemplate.getForObject("http://user/check?username="+username+"&password="+password,boolean.class);

    }
}
